package com.baymax.test.scene.demo

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ScrollView
import com.baymax.test.scene.BaseScene
import com.facebook.drawee.view.SimpleDraweeView
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayout
import com.google.android.flexbox.JustifyContent
import com.google.android.material.transition.MaterialSharedAxis

/**
 * @title:       标题
 * @project:     TestScene
 * @package:     com.baymax.test.scene
 * @class:       KeyScene
 * @description:
 * <p>
 * 类描述
 * </p>
 *
 * @version:   1.0
 * @createDate:   2022/2/23 15:24
 * @Copyright (C) 2022 YSTEN
 * @author:       xuyujian
 */
class KeyScene : BaseScene() {

    val pics = arrayListOf(
        "https://img2.baidu.com/it/u=1027832904,1257430314&fm=253&fmt=auto&app=138&f=GIF?w=400&h=300",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhbimg.huabanimg.com%2Fc6f5daf28ba5dc518fcaea5a7b6fd19c0848cac64d35-uCN42Z_fw658&refer=http%3A%2F%2Fhbimg.huabanimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651479117&t=36d0f56a9b9d24aab2df7dfe6a677045",
        "https://tse1-mm.cn.bing.net/th/id/OET.a0970498c5484f2dbd6ec1de8212587b?w=272&h=272&c=7&rs=1&o=5&pid=1.9",
        "https://tse4-mm.cn.bing.net/th/id/OIP-C.Uo8GDx8CDM92rJNqgwMzUAHaFj?w=240&h=180&c=7&r=0&o=5&pid=1.7",
        "https://tse1-mm.cn.bing.net/th/id/OIP-C.YTSSCjX5Unnh17dVbXHFGgGQEs?w=237&h=180&c=7&r=0&o=5&pid=1.7",
        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fassets.pushthink.com%2Fuploads%2Fphoto%2Fimage%2F368614%2F0020c057928d8d20fd09e8f7e53cafa3.jpg&refer=http%3A%2F%2Fassets.pushthink.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651479117&t=32a0b600d1959413060e54a1b826e03e",
    )

    override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): View {
        return ScrollView(p1.context).apply {
            addView(FlexboxLayout(p1.context).apply {
                flexWrap = FlexWrap.WRAP
                justifyContent = JustifyContent.SPACE_AROUND
            } )
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val flex = (view as ViewGroup).getChildAt(0) as FlexboxLayout
        repeat(100) {
            flex.addView(newImg(view.context, it))
        }
        val l = listOf(1 ,2,3)
        l.reversed()
        l.asReversed()
    }

    fun newImg(ctx: Context, i: Int): View {
        return SimpleDraweeView(ctx).apply {
            setImageURI(pics[i % pics.size])
            maxWidth = 300
            minimumWidth = 300
            maxHeight = 300
            minimumHeight = 300
            background = GradientDrawable().apply {
                setStroke(1, Color.RED)
            }
            post {
                println("wh ${this.height} - ${this.width}")
            }
        }
    }
}